package com.example.guiguihomemedical.controller;

import com.example.guiguihomemedical.common.Result;
import com.example.guiguihomemedical.entity.Servicepack;
import com.example.guiguihomemedical.entity.Signing;
import com.example.guiguihomemedical.service.ServicepackService;
import com.example.guiguihomemedical.service.SigningService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("servicepack")
public class ServicepackController {
    @Autowired
    private ServicepackService servicepackService;
    @GetMapping
    public Result getAll(){
        List<Servicepack> servicepackList = servicepackService.getAll();
        return Result.success(servicepackList);
    }
    @DeleteMapping("/{id}")
    public Result delete(@PathVariable Integer id){
        servicepackService.delete(id);
        return Result.success();
    }

    @PostMapping
    public Result add(@RequestBody Servicepack servicepack){
        servicepackService.add(servicepack);
        return Result.success();
    }

    @GetMapping("/id/{id}")
    public Result getById(@PathVariable Integer id){
        Servicepack servicepack = servicepackService.getById(id);
        return Result.success(servicepack);
    }
    @GetMapping("/name/{name}")
    public Result getByName(@PathVariable String name){
        List<Servicepack> servicepackList = servicepackService.getByName(name);

        return Result.success(servicepackList);
    }
    @PutMapping
    public Result update(@RequestBody Servicepack servicepack){
        servicepackService.update(servicepack);
        return Result.success();
    }
    @GetMapping("/Type")
    public Result getByType(@RequestParam(required = false, value = "type") String type){
        List<Servicepack> servicepack = servicepackService.getByType(type);
        return Result.success(servicepack);
    }
}
